﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //Tablewidget控件
    //设置列数
    ui->tableWidget->setColumnCount(3);

    //设置水平表头
    ui->tableWidget->setHorizontalHeaderLabels(QStringList() << QStringLiteral("姓名")
                                               <<QStringLiteral("性别")<< QStringLiteral("年龄"));

    //设置行数
    ui->tableWidget->setRowCount(5);

    //设置正文
    //ui->tableWidget->setItem(0,0,new QTableWidgetItem(QStringLiteral("亚瑟")));
    QStringList namelist;
    namelist << QStringLiteral("亚瑟") << QStringLiteral("刘备") << QStringLiteral("张飞")
             << QStringLiteral("关羽") << QStringLiteral("赵云");
    QList<QString> sexlist;
    sexlist << QStringLiteral("男") << QStringLiteral("男") << QStringLiteral("男")
            << QStringLiteral("男") <<QStringLiteral("男");

    for (int i = 0 ; i < 5 ;i++)
    {
        int col =0;
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(namelist[i]));
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(sexlist.at(i)));
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(QString::number(i+18))); //int转QString
    }
}

Widget::~Widget()
{
    delete ui;
}
